package com.yqyd.hy.service.impl;

import java.util.List;

import com.yqyd.hy.domain.HyCategory;
import com.yqyd.hy.mapper.HyCategoryMapper;
import com.yqyd.hy.mapper.HyGoodsMapper;
import com.yqyd.hy.service.IHyCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 宏悦—分类Service业务层处理
 * 
 * @author Dhq
 * @date 2025-06-16
 */
@Service
public class HyCategoryServiceImpl implements IHyCategoryService
{
    @Autowired
    private HyCategoryMapper hyCategoryMapper;
    @Autowired
    private HyGoodsMapper hyGoodsMapper;

    /**
     * 查询宏悦—分类
     * 
     * @param id 宏悦—分类主键
     * @return 宏悦—分类
     */
    @Override
    public HyCategory selectHyCategoryById(Long id)
    {
        return hyCategoryMapper.selectHyCategoryById(id);
    }

    /**
     * 查询宏悦—分类列表
     * 
     * @param hyCategory 宏悦—分类
     * @return 宏悦—分类
     */
    @Override
    public List<HyCategory> selectHyCategoryList(HyCategory hyCategory)
    {
        return  hyCategoryMapper.selectHyCategoryList(hyCategory);
    }

    @Override
    public List<HyCategory> selectHyCategoryListApp(HyCategory hyCategory)
    {
        List<HyCategory> list = hyCategoryMapper.selectHyCategoryList(hyCategory);
        for (HyCategory info : list){
            info.setChildren(hyGoodsMapper.selectHyGoodsListByCategoryId(info.getId()));
        }
        // 移除掉没有商品的分类
        list.removeIf(item -> item.getChildren().isEmpty());
        return list;
    }


    /**
     * 新增宏悦—分类
     * 
     * @param hyCategory 宏悦—分类
     * @return 结果
     */
    @Override
    public int insertHyCategory(HyCategory hyCategory)
    {
        return hyCategoryMapper.insertHyCategory(hyCategory);
    }

    /**
     * 修改宏悦—分类
     * 
     * @param hyCategory 宏悦—分类
     * @return 结果
     */
    @Override
    public int updateHyCategory(HyCategory hyCategory)
    {
        return hyCategoryMapper.updateHyCategory(hyCategory);
    }

    /**
     * 批量删除宏悦—分类
     * 
     * @param ids 需要删除的宏悦—分类主键
     * @return 结果
     */
    @Override
    public int deleteHyCategoryByIds(Long[] ids)
    {
        return hyCategoryMapper.deleteHyCategoryByIds(ids);
    }

    /**
     * 删除宏悦—分类信息
     * 
     * @param id 宏悦—分类主键
     * @return 结果
     */
    @Override
    public int deleteHyCategoryById(Long id)
    {
        return hyCategoryMapper.deleteHyCategoryById(id);
    }
}
